<template>
  <ea-dialog
    v-bind="$attrs"
    v-on="$listeners"
    width="300px"
    ref="elDialog"
    :title="title"
    :type="type"
    @submit="submit"
    @reset="$refs.form.resetFields()"
    @closed="end"
  >
    <el-form ref="form" :rules="rules" :model="singleData" label-width="100px">
      <el-form-item label="角色编码" prop="rolecode">
        <el-input
          v-model="singleData.rolecode"
          placeholder="请输入角色编码"
        ></el-input>
      </el-form-item>
      <el-form-item label="角色名称" prop="rolename">
        <el-input
          v-model="singleData.rolename"
          placeholder="请输入角色名"
        ></el-input>
      </el-form-item>
      <el-form-item label="描述" prop="description">
        <el-input
          v-model="singleData.description"
          placeholder="请输入描述"
        ></el-input>
      </el-form-item>
    </el-form>
  </ea-dialog>
</template>

<script>
import editAndAdd from "@/mixins/business/editAndAdd";

export default {
  name: "EaRole",
  mixins: [editAndAdd],
  data() {
    return {
      moduleName: "角色",
      singleData: {
        description: "",
        rolecode: "",
        roleid: 0,
        rolename: ""
      },
      rules: {
        rolecode: { required: true, message: "请输入角色编码" },
        rolename: { required: true, message: "请输入角色名" }
      }
    };
  },
  methods: {
    handle() {
      if (this.type === "add") this.singleData.roleid = null;
      return new Promise((resolve, reject) => {
        this.axios
          .post("/sys/manage/addOrUpdateRole", this.singleData)
          .then(resolve)
          .catch(reject);
      });
    }
  }
};
</script>

<style scoped></style>
